home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-14 | 8.9 KB | 395 lines | [TEXT/MMCC] |
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
- //
- // Horrible Rickety Shell, by Dave Johnson
- //
- // © Copyright 1985 - 1994 Anyone Who Wants It,
- // All Rights Energetically Heaved as far away from me as possible.
- // Use at your own (considerable) risk.
-
-
- #include "AppInterface.h"
- #include <GestaltEqu.h>
-
- /* The two shell globals we need */
- extern MenuHandle gShellMenuHandles[];
- extern Boolean gDoneFlag;
-
- ////////////////
- // Constants
-
- #define kBatchMenuID 131
- #define iBatch 1
-
- ////////////////
- // Globals
-
- WindowRecord gWStore;
- WindowPtr gWindow = nil;
- MenuHandle gBatchMenuHndl = nil;
-
- // Protos for SelectFolder
- void InitSelectFolder(void);
-
-
- // An Apple Event support routine
- OSErr MyGotRequiredParams (AppleEvent *theAEvent);
-
- /* A chance to pre-handle an event */
- Boolean AppDoEvent(EventRecord *event)
- {
- Boolean handled = false;
-
- // Do Stuff
- return handled;
- }
-
- /* Called by the Shell at startup time */
- Boolean AppInit(void) /* returns false if initialization fails */
- {
- Rect tempRect = {0, 0, 300, 300};
- long gestaltResponse;
- OSErr err;
-
- // Check for Apple Event Manager
- err = Gestalt(gestaltAppleEventsAttr, &gestaltResponse);
- if( err != noErr || !(gestaltResponse & (1L >> gestaltAppleEventsPresent)) )
- return false;
-
- // Get the menu, draw menu bar
- gBatchMenuHndl = GetMenu(kBatchMenuID);
- if(gBatchMenuHndl == nil)
- return false;
- (*gBatchMenuHndl)->menuID = kBatchMenuID;
- InsertMenu(gBatchMenuHndl, 0);
-
- DrawMenuBar();
-
- // Install the Apple Event Handlers
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, &AppOAPPHandler, 0, FALSE);
- if(err != noErr)
- return false;
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, &AppODOCHandler, 0, FALSE);
- if(err != noErr)
- return false;
- err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, &AppPDOCHandler, 0, FALSE);
- if(err != noErr)
- return false;
- err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, &AppQUITHandler, 0, FALSE);
- if(err != noErr)
- return false;
-
- // Initialize the select folder stuff
- InitSelectFolder();
-
- // Build a window, invisible
- OffsetRect(&tempRect, 20, GetMBarHeight() + 30);
- gWindow = NewCWindow(&gWStore, &tempRect, "\pA Window", false,
- documentProc, (WindowPtr)(-1), true, nil);
-
- return (gWindow != nil);
- }
-
- /* Called when the shell receives an Activate event. */
- void AppActivate(WindowPtr wind, Boolean activate)
- {
- }
-
- /* Called when a window needs updating. BeginUpdate() has already been called, and the
- port is set to the appropriate window */
- void AppUpdate(EventRecord *event)
- {
- if((WindowPtr) event->message == gWindow)
- {
- EraseRect(&gWindow->portRect);
- }
- }
-
- /* Called when the shell recieves a null event. */
- void AppIdle(EventRecord *Event)
- {
- }
-
- /* Called when there is a click in the content of a window. The port is already set to
- the window, and thePt is in local coords. */
- void AppClick(Point thePt, WindowPtr whichWindptr, Boolean doubleClick)
- {
- }
-
- /* Called when there is a click in the grow region. */
- void AppGrowWindow(WindowPtr wind, Point where, Rect *desk)
- {
- }
-
- /* Called when the user clicks in the zoom box of a window. */
- void AppZoomWindow(WindowPtr wind, short zoomDir)
- {
- }
-
- /* Called when there is a click in the menu bar, before the menu is shown. This is
- the app's opportunity to enable and disable menu items. */
- void AppAdjustMenus()
- {
- }
-
- /* called when a menu other than Apple, File, or Edit is used. */
- void AppMenu(short id, short item)
- {
- // Prototype
- OSErr DoBatchClutStrip(void);
-
- // Batch menu
- if(id == kBatchMenuID)
- {
- OSErr err;
-
- // Only one item in menu
- SetPort(gWindow);
- err = DoBatchClutStrip();
- if(err != noErr)
- DebugStr("\pError in DoBatchClutStrip");
- }
- }
-
- /* Called when the user selects "New" from the File menu. */
- void AppNew(void)
- {
- }
-
- /* Called when the user selects "Open" from the File menu. */
- void AppOpen(void)
- {
- }
-
-
- /* Called when the user selects "Close" from the File menu or clicks the close box
- of a window. */
- Boolean AppClose(void)
- {
- /* returns false if the user cancels the save */
-
- return true;
- }
-
- /* Called when the user selects "Save" from the File menu. */
- Boolean AppSave(void)
- {
- /* returns false if the user cancels the save */
- return true;
- }
-
- /* Called when the user selects "Save As..." from the File menu. */
- Boolean AppSaveAs(void)
- {
- /* returns false if the user cancels the save */
- return true;
- }
-
- /* Called when the user selects "Page Setup..." from the File menu. */
- void AppPageSetup(void)
- {
- }
-
- /* Called when the user selects "Print..." from the File menu. */
- void AppPrint(void)
- {
- }
-
- /* Called when the user selects "Undo" from the Edit menu. */
- void AppUndo(void)
- {
- }
-
- /* Called when the user selects "Cut" from the Edit menu. */
- void AppCut(void)
- {
- }
-
- /* Called when the user selects "Copy" from the Edit menu. */
- OSErr AppCopy(void)
- {
- return noErr;
- }
-
- /* Called when the user selects "Paste" from the Edit menu. */
- void AppPaste(void)
- {
- }
-
- /* Called when the user selects "Clear" from the Edit menu. */
- void AppClear(void)
- {
- }
-
- /* Called when the user chooses "Quit" from the File menu. If the user cancels
- the save it returns false, otherwise it returns true and the shell quits */
- Boolean AppQuit(void)
- {
- /* returns false if the user cancels the save at any point */
- return true;
- }
-
- /* Called when the shell is about to quit, just deallocates memory. */
- void AppCleanUp(void)
- {
- if(gWindow != nil)
- {
- CloseWindow(gWindow);
- gWindow = nil;
- }
- }
-
- /* Apple Event handlers */
- pascal OSErr AppOAPPHandler(AppleEvent *theAEvent, AppleEvent *reply, long refcon)
- {
- OSErr err;
-
- err = MyGotRequiredParams(theAEvent);
- if (err)
- return err;
- else {
- // Just do an AppNew()
- AppNew();
- return noErr;
- }
- }
-
- pascal OSErr AppODOCHandler(AppleEvent *theAEvent, AppleEvent *reply, long refcon)
- {
- FSSpec myFSS;
- AEDescList docList;
- OSErr err;
- long index, itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
-
- // get the direct parameter--a descriptor list--and put
- // it into docList
- err = AEGetParamDesc(theAEvent, keyDirectObject,
- typeAEList, &docList);
- if (err)
- return err;
-
- // check for missing required parameters
- err = MyGotRequiredParams(theAEvent);
- if (err) {
- // an error occurred: do the necessary error handling
- err = AEDisposeDesc(&docList);
- return err;
- }
-
- // count the number of descriptor records in the list
- err = AECountItems (&docList, &itemsInList);
-
- // now get each descriptor record from the list, coerce
- // the returned data to an FSSpec record, and open the
- // associated file
- for (index = 1; index <= itemsInList; index++)
- {
- err = AEGetNthPtr(&docList, index, typeFSS, &keywd,
- &returnedType, (Ptr)&myFSS,
- sizeof(myFSS), &actualSize);
- if (err)
- SysBeep(10);
-
- // Open the file
- SysBeep(10); // Sorry, no files to open yet
-
- if (err)
- SysBeep(10);
- }
-
- err = AEDisposeDesc(&docList);
- return noErr;
- }
-
- pascal OSErr AppPDOCHandler(AppleEvent *theAEvent, AppleEvent *reply, long refcon)
- {
- FSSpec myFSS;
- AEDescList docList;
- OSErr err;
- long index, itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
-
- // get the direct parameter--a descriptor list--and put
- // it into docList
- err = AEGetParamDesc(theAEvent, keyDirectObject,
- typeAEList, &docList);
- if (err)
- return err;
-
- // check for missing required parameters
- err = MyGotRequiredParams(theAEvent);
- if (err) {
- // an error occurred: do the necessary error handling
- err = AEDisposeDesc(&docList);
- return err;
- }
-
- // count the number of descriptor records in the list
- err = AECountItems (&docList, &itemsInList);
-
- // now get each descriptor record from the list, coerce
- // the returned data to an FSSpec record, and open the
- // associated file
- for (index = 1; index <= itemsInList; index++)
- {
- err = AEGetNthPtr(&docList, index, typeFSS, &keywd,
- &returnedType, (Ptr)&myFSS,
- sizeof(myFSS), &actualSize);
- if (err)
- SysBeep(10);
-
- // Print the file
- SysBeep(10);
-
- if (err)
- SysBeep(10);
- }
-
- err = AEDisposeDesc(&docList);
- return noErr;
- }
-
- pascal OSErr AppQUITHandler(AppleEvent *theAEvent, AppleEvent *reply, long refcon)
- {
- OSErr err;
-
- // check for missing required parameters
- err = MyGotRequiredParams(theAEvent);
- if (err) {
- // an error occurred: do the necessary error handling
- return err;
- }
-
- // Set the global flag if the user doesn't cancel
- gDoneFlag = AppQuit();
- if(gDoneFlag == false)
- return userCanceledErr;
- else
- return noErr;
- }
-
- OSErr MyGotRequiredParams (AppleEvent *theAEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr err;
-
- err = AEGetAttributePtr(theAEvent, keyMissedKeywordAttr,
- typeWildCard, &returnedType,
- nil, 0, &actualSize);
-
- if (err == errAEDescNotFound) // you got 'em all
- return noErr;
- else
- if (err == noErr) // you missed a required parameter
- return errAEParamMissed;
- else // the call to AEGetAttributePtr failed
- return err;
- }
-
-